﻿#region File and License Information
/*
<File>
	<License Type="BSD">
		Copyright © 2009 - 2012, Outcoder. All rights reserved.
	
		This file is part of Calcium (http://calciumsdk.net).

		Redistribution and use in source and binary forms, with or without
		modification, are permitted provided that the following conditions are met:
			* Redistributions of source code must retain the above copyright
			  notice, this list of conditions and the following disclaimer.
			* Redistributions in binary form must reproduce the above copyright
			  notice, this list of conditions and the following disclaimer in the
			  documentation and/or other materials provided with the distribution.
			* Neither the name of the <organization> nor the
			  names of its contributors may be used to endorse or promote products
			  derived from this software without specific prior written permission.

		THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
		ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
		WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
		DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
		DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
		(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
		LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
		ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
		(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
		SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	</License>
	<Owner Name="Daniel Vaughan" Email="danielvaughan@outcoder.com" />
	<CreationDate>2009-03-01 18:43:44Z</CreationDate>
</File>
*/
#endregion

using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;

namespace Outcoder.ServiceModel
{
	/// <summary>
	/// Use <code>IChannelManager</code> to create simplex and duplex WCF channels.
	/// </summary>
	public interface IChannelManager
	{
		/* TODO: Update documentation to remove references to deprecated StaticFactory. */

		/// <summary>
		/// Creates or retrieves a cached service channel.
		/// <example>
		/// var staticFactoryConfiguration = unityContainer.Configure<IStaticFactoryConfiguration>();
		///	Debug.Assert(staticFactoryConfiguration != null);
		///	if (staticFactoryConfiguration != null)
		///	{
		///		staticFactoryConfiguration.RegisterFactory<IYourService>(
		///			ChannelManagerSingleton.Instance.GetChannel<IYourService>);
		/// 
		///		/* Attempt to retrieve and use the service. */
		///		var yourService = Dependency.Resolve<IYourService>();
		///		yourService.DoSomething();
		/// }
		/// </example>
		/// </summary>
		/// <returns>A channel of the specified type.</returns>
		/// <exception cref="CommunicationException">Occurs if the service implements <see cref="IServiceContract"/>, 
		/// and the call to InitiateConnection results in a <code>CommunicationException</code></exception>
		/// <exception cref="SecurityNegotiationException">Occurs if the service implements <see cref="IServiceContract"/>, 
		/// and the call to InitiateConnection results in a <code>SecurityNegotiationException</code></exception>
		TService GetChannel<TService>();

		/// <summary>
		/// Creates a duplex service channel.
		/// <example>
		/// var channelManager = unityContainer.Resolve&lt;IChannelManager&gt;();
		/// var myService = channelManager.GetDuplexChannel<IMyService>(new MyServiceCallback());
		/// </example>
		/// </summary>
		/// <param name="callbackInstance">Is used to respond to server side me</param>
		/// <returns>A channel of the specified type.</returns>
		/// <exception cref="CommunicationException">Occurs if the service implements <see cref="IServiceContract"/>, 
		/// and the call to InitiateConnection results in a <code>CommunicationException</code></exception>
		/// <exception cref="SecurityNegotiationException">Occurs if the service implements <see cref="IServiceContract"/>, 
		/// and the call to InitiateConnection results in a <code>SecurityNegotiationException</code></exception>
		/// <exception cref="StudioException">Occurs if the specified <code>TCallback</code> 
		/// type is unable to be resolved by the specified unity container.</exception>
		TService GetDuplexChannel<TService>(object callbackInstance);

		/// <summary>
		/// Allows a binding and endpoint to be associated with the specified channel type.
		/// Using this method will take precedence over a config binding.
		/// </summary>
		/// <param name="channelType">Type of the channel.</param>
		/// <param name="binding">The binding.</param>
		/// <param name="endPointAddress">The end point address.</param>
		/// <exception cref="ArgumentNullException">
		/// Occurs if any argument is <c>null</c>.</exception>
		void SetBinding(Type channelType, Binding binding, EndpointAddress endPointAddress);
	}
}
